package com.big.merchan.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.big.cmn.DictFeignClient;
import com.big.merchan.mapper.MerchandiseSpecificationMapper;
import com.big.merchan.service.MerchandiseSpecificationService;
import com.big.model.model.merchandise.MerchandiseSpecification;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class MerchandiseSpecificationServiceImpl extends ServiceImpl<MerchandiseSpecificationMapper, MerchandiseSpecification> implements MerchandiseSpecificationService {


    @Autowired
    DictFeignClient dictFeignClient;

    @Override
    public MerchandiseSpecification findSpecification(String mId) {
        QueryWrapper<MerchandiseSpecification>queryWrapper=new QueryWrapper<>();
        if(!StringUtils.isEmpty(mId)){
            queryWrapper.eq("m_id",mId);
        }
        MerchandiseSpecification merchandiseSpecification = baseMapper.selectOne(queryWrapper);
        String name = dictFeignClient.getName(String.valueOf(merchandiseSpecification.getMType()));
        switch (name) {
            case "笔记本" :
                //笔记本属性
                this.specificationComputer(merchandiseSpecification);
                break;
            case "手机" :
                //手机属性
                this.specificationPhone(merchandiseSpecification);
                break;
        }
        return merchandiseSpecification;
    }

    /**
     * 规格字典信息
     */
   public MerchandiseSpecification specificationComputer(MerchandiseSpecification specification  ){

       //硬盘规格
       String hddName = dictFeignClient.getSpeName(String.valueOf(specification.getHdd()));

       //运行内存
       String runMemoryName = dictFeignClient.getSpeName(String.valueOf(specification.getRunMemory()));

       //cpu
       String cpuName = dictFeignClient.getSpeName(String.valueOf(specification.getCpu()));

       //显卡
       String gpuName = dictFeignClient.getSpeName(String.valueOf(specification.getGpu()));

       //操作系统
       String operatingSystemName = dictFeignClient.getSpeName(String.valueOf(specification.getOperatingSystem()));

       //品牌
       String brandName = dictFeignClient.getSpeName(String.valueOf(specification.getBrand()));

       specification.getParam().put("hddName",hddName);
       specification.getParam().put("runMemoryName",runMemoryName);
       specification.getParam().put("cpuName",cpuName);
       specification.getParam().put("gpuName",gpuName);
       specification.getParam().put("operatingSystemName",operatingSystemName);
       specification.getParam().put("brandName",brandName);

       return specification;
   }

    /**
     * 规格字典信息
     */
    public MerchandiseSpecification specificationPhone(MerchandiseSpecification specification  ){

        //硬盘规格
        String hddName = dictFeignClient.getSpeName(String.valueOf(specification.getHdd()));

        //运行内存
        String runMemoryName = dictFeignClient.getSpeName(String.valueOf(specification.getRunMemory()));

        //cpu
        String cpuName = dictFeignClient.getSpeName(String.valueOf(specification.getCpu()));

        //操作系统
        String operatingSystemName = dictFeignClient.getSpeName(String.valueOf(specification.getOperatingSystem()));

        //品牌
        String brandName = dictFeignClient.getSpeName(String.valueOf(specification.getBrand()));

        //通信
        String telecomName = dictFeignClient.getSpeName(String.valueOf(specification.getTelecom()));

        //后置摄像头
        String cameraName = dictFeignClient.getSpeName(String.valueOf(specification.getCamera()));

        //电池容量
        String batteryCapacity = dictFeignClient.getSpeName(String.valueOf(specification.getBatteryCapacity()));

        specification.getParam().put("hddName",hddName);
        specification.getParam().put("runMemoryName",runMemoryName);
        specification.getParam().put("cpuName",cpuName);
        specification.getParam().put("operatingSystemName",operatingSystemName);
        specification.getParam().put("brandName",brandName);
        specification.getParam().put("telecomName",telecomName);
        specification.getParam().put("cameraName",cameraName);
        specification.getParam().put("batteryCapacity",batteryCapacity);
        return specification;
    }

}
